<?php

namespace app\adminapi\controller\v1\setting\admin;

use app\adminapi\controller\AuthController;
use app\services\setting\admin\SystemRoleService;
use think\facade\App;

class SystemRole extends AuthController
{

    public function __construct(App $app,SystemRoleService $service)
    {
        parent::__construct($app);
        $this ->services = $service;
    }

    public function index()
    {
        $where = $this->request->getMore([
            ['page',1],
            ['pageSize',20]
        ]);
        return app() -> make('json') -> successful($this -> services -> index($where));

    }

    /**
     * 创建角色
     * @return void
     */
    public function create()
    {
        $where = $this->request->postMore([
            ['title',''],
            ['status',1],
            ['rules',''],
            ['weight',0],
            ['remark',''],
            ['pid',''],
        ]);
        $where['website_id'] = $this -> request -> header('website');

        return app() -> make('json') -> successful($this -> services -> create($where));
    }


    /**
     * 编辑
     * @return void
     */
    public function update()
    {
        $where = $this->request->postMore([
            ['title',''],
            ['status',''],
            ['rules',''],
            ['weight',0],
            ['remark',''],
            ['id',''],
            ['pid',''],
        ]);
        $where['website_id'] = $this -> request -> header('website');

        return app() -> make('json') -> successful($this -> services -> update($where));
    }

    /**
     * 编辑
     * @return void
     */
    public function delete()
    {
        $where = $this->request->postMore([
            ['id',''],
        ]);
        return app() -> make('json') -> successful($this -> services -> delete($where));
    }

    /**
     * 搜索角色名称
     * @return mixed
     */
    public function searchTitle(){
        $where = $this->request->postMore([
            ['title',''],
            ['page',1],
            ['pageSize',20]
        ]);
        return app() -> make('json') -> successful($this -> services -> searchTitle($where));
    }









}